/**
 * 打印队列状态通知组件导出
 */

import { createApp, h } from 'vue'
import PrintQueueNotification from './index.vue'
import printQueueNotificationService from './service'

/**
 * 创建并挂载打印队列通知组件
 */
export function createPrintQueueNotification() {
    // 检查是否已经存在
    const existingElement = document.getElementById('print-queue-notification')
    if (existingElement) {
        console.warn('打印队列通知组件已存在')
        return
    }

    // 创建容器
    const container = document.createElement('div')
    container.id = 'print-queue-notification'

    // 创建Vue应用
    const app = createApp({
        render() {
            return h(PrintQueueNotification)
        }
    })

    // 挂载应用
    app.mount(container)

    // 添加到body
    document.body.appendChild(container)

    console.log('打印队列通知组件已创建并挂载')

    return {
        destroy() {
            app.unmount()
            if (container.parentNode) {
                container.parentNode.removeChild(container)
            }
            printQueueNotificationService.unregisterInstance()
        }
    }
}

/**
 * 获取打印队列通知服务实例
 */
export function getPrintQueueNotificationService() {
    return printQueueNotificationService
}

// 默认导出服务
export default printQueueNotificationService
